<template>
  <div id="app" v-bind:style="appDivStyle">
      <div class="context" ref="context">
           <div class="queryBox" ref="queryBox">
                <el-form :inline="true" :model="formQueryCondition"
                         ref="form" size="mini">
                    <el-form-item :label="$t('Language.queryLabel.languageName')"   :label-width="queryformLabelWidthLong">
                        <el-input v-model.trim="formQueryCondition.languageName.val" class="queryItemStyle" clearable
                                  :placeholder="$t('Language.queryLabel.placeholderLanguageName')">
                        </el-input>
                    </el-form-item>
                    <el-form-item :label="$t('Language.queryLabel.status')"  :label-width="queryformLabelWidth">
                        <el-select v-model="formQueryCondition.status.val" class="queryItemStyle">
                            <el-option :label="$t('label.all')" value=""></el-option>
                            <el-option :label="$t('label.available')" value="Available"></el-option>
                            <el-option :label="$t('label.invalid')" value="Invalid"></el-option>
                        </el-select>
                    </el-form-item>


                    <div style="text-align:right">
                        <el-form-item>
                            <el-button type="primary" v-if="test('onNewBtn')" 
                            @click="onNew">{{ $t('btnText.newBtnText') }}</el-button>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="onReset('form')">{{ $t('btnText.resetBtnText') }}</el-button>
                        </el-form-item>
                        <!-- <el-form-item>
                            <el-button type="primary" @click="onExport" icon="el-icon-download" :loading="loading">{{ $t('btnText.exportBtnText') }}</el-button>
                        </el-form-item> -->
                        <el-form-item>
                            <el-button type="primary" @click="onQuery" icon="el-icon-search" :loading="loading">{{ $t('btnText.queryBtnText') }}</el-button>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
            <div class="dataBox" ref="dataBox">
                
                <transition enter-active-class="animated zoomIn" leave-active-class="animated rotateOut">
                    <el-table v-if="isInit" ref="singleTable"
                                :data="tableData"
                                :height="tableHeight"
                                @sort-change="sortChange"
                                v-loading="loading" size="mini"
                                style="width: 100%;" stripe=stripe border=border>
                        <el-table-column type="index"  width="50" fixed="left"
                                            :label="$t('table.xh')" align="center">
                        </el-table-column>
                        <el-table-column :label="$t('table.op')" fixed="left" min-width="150">
                            <template slot-scope="scope">
                                <el-button size="gv" icon="el-icon-edit" :loading="loading"
                                @click="edit(scope.$index, scope.row)"
                                            >{{ $t('btnText.editBtnText') }}</el-button>
                                <!-- <el-button size="gv" icon="el-icon-delete"
                                            type="danger" :loading="loading" @click="deleteRow(scope.$index, scope.row)"
                                            >{{ $t('btnText.deleteBtnText') }}</el-button> -->
                                <el-button size="gv" icon="el-icon-delete"
                                            type="danger" :loading="loading" @click="logoffRow(scope.$index, scope.row)"
                                            >{{ $t('btnText.logoffBtnText') }}</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="languageCode" min-width="140" fixed="left"
                                            :label="$t('Language.table.languageCode')" sortable="custom" sort-by="languageCode">
                        </el-table-column>
                        <el-table-column prop="languageName" min-width="140" fixed="left"
                                            :label="$t('Language.table.languageName')" sortable="custom" sort-by="languageName">
                        </el-table-column>
                        <el-table-column prop="status" min-width="130" 
                        :label="$t('Language.table.status')" sortable="custom" sort-by="status">
                        </el-table-column>

                        <el-table-column :label="$t('Language.table.lastUpdatedBy')" min-width="120" sortable="custom" prop="lastUpdatedBy" sort-by="lastUpdatedBy">
                        </el-table-column>
                        <el-table-column :label="$t('Language.table.lastUpdateTime')" min-width="180" sortable="custom" prop="lastUpdateTime" sort-by="lastUpdateTime">
                        </el-table-column>

                    </el-table>
                </transition>
               
            </div>
        </div>
        <div class="pageBox">
            <el-pagination @size-change="sizeChange" 
                            @current-change="currentPageChange"
                            :current-page="pager.curPage"
                            :page-sizes="pager.sizes"
                            :page-size="pager.curSize"
                            :background="true"
                            layout="total, sizes, prev, pager, next, jumper" :total="pager.total">
            </el-pagination>
        </div>

         <!--编辑对话框-->
        <transition enter-active-class="animated rotateIn" leave-active-class="animated rotateOut">
            <el-dialog :title="$t('label.dialogTitle')" :visible.sync="isShowEditForm" top="5vh">
                <el-form :model="editForm" ref="editForm" size="mini"
                        :label-position="editFormPosition" status-icon=status-icon :rules="editRules">
                    <el-form-item :label="$t('Language.editLabel.languageCode')" v-if="isShow"
                        :label-width="editformLabelWidth" prop="languageCode">
                        <el-input v-model.trim="editForm.languageCode" maxlength="20" :disabled="true"
                                :placeholder="$t('Language.editLabel.placeholderLanguageCode')"></el-input>
                    </el-form-item>
                    <el-form-item :label="$t('Language.editLabel.languageName')" 
                        :label-width="editformLabelWidth" prop="languageName">
                        <el-input v-model.trim="editForm.languageName" maxlength="50"
                                :placeholder="$t('Language.rules.placeholderLanguageName')"></el-input>
                    </el-form-item>

                    <el-form-item :label="$t('Language.editLabel.status')" 
                        :label-width="editformLabelWidth" prop="status">
                        <el-select v-model="editForm.status" class="queryItemStyle">
                            <el-option :label="$t('label.available')" value="Available"></el-option>
                            <el-option :label="$t('label.invalid')" value="Invalid"></el-option>
                        </el-select>
                    </el-form-item>
                    
                </el-form>
                <div slot="footer">
                    <el-button size="mini" @click="isShowEditForm = false" :loading="loading">{{ $t('btnText.cancelBtnText') }}</el-button>
                    <el-button size="mini" type="primary" @click="submitForm('editForm')" :loading="loading">{{ $t('btnText.saveBtnText') }}</el-button>
                </div>
            </el-dialog>
        </transition>
        
  </div>
    
 
</template>

<script>

import comBaseVue from '../../baseViewModel';

export default {
  mixins: [comBaseVue],
  name:'Language',
  data () {
    
    return {
        queryformLabelWidthLong:"110px",
        isInit:false,
        isShow:false,
        tableHeight:100,
        appDivStyle:{
            height:this.$store.getters.appHeight,
        },
        modelName:"system.model.Language",
        // 查询条件
        formQueryCondition: {
            languageName: {
                
                //mapName: 'code.key',  映射的别名 在同时查询一个属性时需要别名
                //gName:'code',   组名
                op: 'LIKE', // 操作符
                val: '' // 查询的值
            },
            status: {
                val: ''
            },
        },
        
        // 编辑面板绑定的对象
        editForm: {
            keyID: 0,
            version: 0,
            languageCode: "",
            languageName: "",
            status: "",
        },
        // 编辑面板的验证规则
        editRules: {
            languageCode: [{ required: true, message: this.$i18n.t('Language.rules.placeholderLanguageCode'), trigger: 'blur' }],
            languageName: [{ required: true, message: this.$i18n.t('Language.rules.placeholderLanguageName'), trigger: 'blur' }],
            // status: [{ required: true, message: this.$i18n.t('Language.rules.placeholderStatus'), trigger: 'blur' }],
        },
        sort:{
            key: "lastUpdateTime",
            dir: "Desc"
        }
    }
  },
  methods:{
      test:function(btnCode){
          return true;
        },
    // 新增  
    onNew: function() {
        this.isShowEditForm = true;
        if (this.$refs['editForm']) {
            this.$refs['editForm'].resetFields();
        }
        this.isShow = false;
        this.editForm.keyID = "";
        this.editForm.version = "";
        this.editForm.languageCode = "";
        this.editForm.languageName = "";
        this.editForm.status = "有效";
        this.curCommand = "SaveNew";
        this.canEditCode = false;
    },
    
     // 重置
    onReset:function(){
        if (this.$refs['form']) {
            this.$refs['form'].resetFields();
        }
        this.formQueryCondition.languageName.val = "";
        this.formQueryCondition.status.val = "";
    },
   
    
    // 授权按钮单击事件
    editMenu: function(index, row) {
        
    },
    
    edit: function(index, row){
        this.queryModelByKeyID(this.modelName,row.keyID,"Query",this.editCallback);
    },
    // 编辑按钮回调事件
    editCallback: function(isSuccess,json) {
        console.info("------");
        console.info(json);
        this.isShow = true;
        if(isSuccess){
            this.curCommand = "UpdateProc";
            this.isShowEditForm = true;
            if (this.$refs['editForm']) {
                this.$refs['editForm'].resetFields();
            }
            this.editForm = json;
            // this.canEditCode = true;
        }
        else{
            this.$message({
                message: json.msg,
                type: 'warning'
                });
        }
    },
    
    initTable:function(){
        this.tableHeight = this.$refs.context.offsetHeight - this.$refs.queryBox.offsetHeight;
        this.isInit = true;
    },
    
    
  },
  mounted: function mounted() {
    this.onQuery();
    window.setTimeout(this.initTable,100); 
    
  }
}


</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    
</style>
